/**
 *  Queue - Stack Implementation
 *
 */

import java.util.Stack;

class QueueStack<T> {
    
    private Stack<T> s1 = new Stack<T>();
    private Stack<T> s2 = new Stack<T>();

    private int total;

    public void enqueue(T t) {
        s1.push(t);
        total++;
    }

    public T dequeue() {
        exchange(s1, s2);

        if (s2.size() == 0) {
            return null;
        }

        T t = s2.pop();
        total--;

        exchange(s2, s1);

        return t;
    }

    public T peek() {
        exchange(s1, s2);

        if (s2.size() == 0) {
            return null;
        }

        T t = s2.peek();
    
        exchange(s2, s1);

        return t;
    }

    public int size() {
        return total;
    }

    public Boolean isEmpty() {
        return total == 0;
    }

    private void exchange(Stack<T> s1, Stack<T> s2) {
        while (s1.size() > 0) {
            s2.push(s1.pop());
        }
    }

}
